home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / ifgate / unpacker.c < prev   
Encoding:
C/C++ Source or Header  |  1994-04-04  |  950 b   |  40 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "lutil.h"
  4. #include "config.h"
  5.  
  6. char *unpacker(fn)
  7. char *fn;
  8. {
  9.     FILE *fp;
  10.     unsigned char buf[8],dbuf[80];
  11.     int i;
  12.  
  13.     if ((fp=fopen(fn,"r")) == NULL) 
  14.     {
  15.         logerr("$Could not open file %s",fn);
  16.         return NULL;
  17.     }
  18.     if (fread(buf,1,sizeof(buf),fp) != sizeof(buf))
  19.     {
  20.         logerr("$Could not read head of the file %s",fn);
  21.         return NULL;
  22.     }
  23.     fclose(fp);
  24.     dbuf[0]='\0';
  25.     for (i=0;i<sizeof(buf);i++)
  26.         if ((buf[i] >= ' ') && (buf[i] <= 127)) 
  27.             sprintf((char*)dbuf+strlen(dbuf),"  %c",buf[i]);
  28.         else
  29.             sprintf((char*)dbuf+strlen(dbuf)," %02x",buf[i]);
  30.     debug(2,"file head: %s",dbuf);
  31.  
  32.     if (memcmp(buf,"PK",2) == 0)         return unzip;
  33.     if (*buf == 0x1a)                    return unarc;
  34.     if (memcmp(buf+2,"-l",2) == 0)       return unlzh;
  35.     if (memcmp(buf,"ZOO",3) == 0)        return unzoo;
  36.     if (memcmp(buf,"`\352",2) == 0)      return unarj;
  37.     logerr("Unknown compress scheme in file %s",fn);
  38.     return NULL;
  39. }
  40.